﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using CWCS.DataAccess;
using System.Data;
using System.Net;
using System.IO;
using LOG;
using CWCS.Core.Library.PLCManager;
using CWCS.Common.Log;
using CWCS.Entity.SRM;
using CWCS.Entity.Convery;
using System.Text.RegularExpressions;
using System.Threading;

namespace CWCS.BLL
{
    public class CRCTask : BLLBase
    {
        private LogHelper log = new LogHelper("SC");
        private BLLSRM bllSrm = new BLLSRM();
        public int testFlag = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["testFlag"]);
        private Hashtable logHt = Hashtable.Synchronized(new Hashtable());
        private bool[] taskht = new bool[7] { false, false, false, false, false, false, false };
        public string UpdateCRCStatus(string scno, string str, string aisle, string zonecode)
        {
            string srmLog = "";
            string[] msg = str.Split(new char[] { ';' });
            CRCStatus SrmInfo = list_srm_info.Find(
                delegate (CRCStatus info)
                {
                    return info.scno == scno;
                }
            );

            if (SrmInfo != null)
            {
                string wcsModeInfo = "任务:" + bllSrm.getTasktype(SrmInfo.TaskType);
                string wcsForkInfo = ".货叉:" + bllSrm.getForktype(SrmInfo.ForkType);
                if (str == "Break")
                {
                    SrmInfo.SCStatus = EQUIPMENT_ERROR;
                    SrmInfo.CraneMode = "0";
                    SrmInfo.RackSide = "1";
                    SrmInfo.RackPosition = "1";
                    SrmInfo.RackPlace = "1";
                    SrmInfo.RackLevel = "1";
                    SrmInfo.RackDepth = "1";
                    SrmInfo.LabelInfo = ".任务号:" + SrmInfo.TaskNo + "," + SrmInfo.TaskNo2 + ".托盘:" + SrmInfo.Barcode + "," + SrmInfo.Barcode2 + ".位置:" + SrmInfo.Position + ".模式:" + "手动" + ".状态:" + "故障" + ".起始:" + SrmInfo.Fromstation + "," + SrmInfo.Fromstation2 + ".目标:" + SrmInfo.Tostation + "," + SrmInfo.Tostation2 + "." + SrmInfo.AlarmMessage;
                    SrmInfo.NewLabelInfo = wcsModeInfo + wcsForkInfo+ SrmInfo.LabelInfo;
                    UpdateSCStatus(WareHouseID, SrmInfo.scno, SrmInfo.SCStatus);//更改堆垛机状态
                }
                else if (str == "Update")
                {
                    SrmInfo.NewLabelInfo = wcsModeInfo + wcsForkInfo + SrmInfo.LabelInfo;
                }
                else if (msg.Length > 38)
                {
                    string SCStatus = EQUIPMENT_ERROR;
                    SrmInfo.SCTaskFlag = "0";
                    int fork2taskno = int.Parse(msg[2].ToString()) * 256 + int.Parse(msg[3].ToString());
                    if (fork2taskno == 256)
                        fork2taskno = 0;
                    int taskno = int.Parse(msg[4].ToString()) * 256 + int.Parse(msg[5].ToString());
                    if (taskno == 256)
                        taskno = 0;
                    //if (taskno != 0 && taskno.ToString() != SrmInfo.TaskNo)
                    //{
                    //    dal.UpdateTaskStatus(taskno.ToString(), "", "SC", "2", "1"); //修改堆垛机任务状态
                    //}
                    SrmInfo.FunctionReport = msg[6];   //动作执行情况报告
                    SrmInfo.FunctionMode = msg[7];     //堆垛机状态报告
                    int[] functionmode = FunctionMode(int.Parse(SrmInfo.FunctionMode));  //自动，半自动   
                    if (functionmode[0] == 1 && functionmode[4] == 1 && functionmode[7] == 0)//自动，就绪、正常
                    {
                        SCStatus = EQUIPMENT_OK;
                        SrmInfo.SCTaskFlag = "1";
                        UpdateSCStatus(WareHouseID, SrmInfo.scno, SCStatus);//更改堆垛机状态
                    }
                    else
                    {
                        UpdateSCStatus(WareHouseID, SrmInfo.scno, SCStatus);//更改堆垛机状态
                    }

                    int[] cranemode = FunctionMode(int.Parse(msg[22]));
                    SrmInfo.TaskNo = taskno.ToString();
                    SrmInfo.TaskNo2 = fork2taskno.ToString();
                    SrmInfo.SCStatus = SCStatus;
                    //if (SrmInfo.TaskNo.Length == 5)
                    //    SrmInfo.Barcode = dal.GetTostation(SrmInfo.TaskNo, "SC")[2];
                    //else
                    //    SrmInfo.Barcode = "";
                    SrmInfo.Total_Alarm = functionmode[7];   //总报警
                    SrmInfo.forkStatus1 = FunctionMode(int.Parse(msg[8]))[0]; //货叉1状态
                    SrmInfo.forkStatus2 = FunctionMode(int.Parse(msg[8]))[1]; //货叉2状态
                    SrmInfo.ActTU = msg[9];  //当前动作的货叉  
                    SrmInfo.ActionPoint = msg[10];    //输送机地址编号 动作端
                    SrmInfo.AisleNumber = msg[11];    //巷道号 01--09
                    SrmInfo.RackSide = msg[12];       //巷道左右边 01左 02右  rack side
                    SrmInfo.RackPosition = msg[13];   //列值         rack field
                    SrmInfo.RackPlace = msg[14];      //货格       rack place
                    SrmInfo.RackLevel = msg[15];      //层值  rack level 1-24
                    SrmInfo.RackDepth = msg[16];      //深度 01--02    
                    SrmInfo.FireFlag = msg[21];      //火警状态：16#01表示检测到烟感信号，16#02表示检测到温感信号，16#03表示同时检测到烟感和温感信号
                    SrmInfo.Position = GetLocation(scno, int.Parse(msg[10]), int.Parse(msg[12]), int.Parse(msg[13]), int.Parse(msg[14]), int.Parse(msg[15]), int.Parse(msg[16]));
                    SrmInfo.AlarmMessage = GetAlarmInfo(scno, "", false) + (msg[21] == "1" ? "烟感报警" : msg[21] == "2" ? "温感报警" : msg[21] == "3" ? "温感、烟感报警" : "");
                    SrmInfo.LabelInfo = ".任务号:" + SrmInfo.TaskNo + "," + SrmInfo.TaskNo2 + ".托盘1:" + SrmInfo.Barcode + ".托盘2:" + SrmInfo.Barcode2 + ".位置:" + SrmInfo.Position + ".模式:" + GetFunctionMode(functionmode, cranemode) + ".状态:" + GetTaskStatusBase(msg[6], msg[24]) + ".起始:" + SrmInfo.Fromstation + "," + SrmInfo.Fromstation2 + ".目标:" + SrmInfo.Tostation + "," + SrmInfo.Tostation2 + "." + SrmInfo.AlarmMessage;
                    //声控报警
                    if ((GetFunctionMode(functionmode, cranemode).Contains("故障") || GetFunctionMode(functionmode, cranemode).Contains("报警")))
                        QueueSpeech.AddQueue(SrmInfo.scno + GetFunctionMode(functionmode, cranemode));
                    if (msg[21] == "1" || msg[21] == "2" || msg[21] == "3")
                        QueueSpeech.AddQueue(SrmInfo.AlarmMessage);

                    if (functionmode[0] == 1 && functionmode[4] == 1 && functionmode[7] == 0)
                    {
                        SrmInfo.Auto = "1";
                    }
                    else if (functionmode[3] == 1 && functionmode[7] == 0)
                    {
                        SrmInfo.Auto = "2";
                    }
                    else
                        SrmInfo.Auto = "0";
                    SrmInfo.NewLabelInfo = wcsModeInfo + wcsForkInfo + SrmInfo.LabelInfo;
                    //显示信息
                    if (SrmInfo.LabelInfo == SrmInfo.OldLabelInfo) //上一次信息
                        SrmInfo.Change = false;
                    else
                    {
                        SrmInfo.OldLabelInfo = SrmInfo.LabelInfo;
                        SrmInfo.Change = true;
                    }
                    #region
                    CRCObject co = list_srm_object.Find(
                         delegate (CRCObject cob)
                         {
                             return (cob.ScNo == scno && cob.Port.ToString().Contains("200"));
                         }
                    );
                    if (co != null)
                    {
                        if (SrmInfo.Auto == "1" || SrmInfo.Auto == "2")
                        {
                            if (SrmInfo.TaskNo.Length == 5)
                            {
                                string[] ss = dal.GetTostation(SrmInfo.TaskNo, "SC");//查询此时任务号对应的SC起始和SC目标地址
                                if (ss != null)
                                {
                                    SrmInfo.Fromstation = ss[0].ToString();
                                    SrmInfo.Tostation = ss[1].ToString();
                                    SrmInfo.Barcode = ss[2].ToString();
                                    SrmInfo.MESLocation = ss[3].ToString();
                                    if (ss[4].ToString() == "0")
                                    {
                                        dal.UpdateTaskStatus(SrmInfo.Fromstation, SrmInfo.TaskNo, "", "SC", "2", "1"); //当任务状态未开始时 再次更新任务状态
                                    }
                                }
                                else
                                {
                                    SrmInfo.Fromstation = "";
                                    SrmInfo.Tostation = "";
                                    SrmInfo.Barcode = "";
                                    SrmInfo.MESLocation = "";
                                }
                            }
                            if (SrmInfo.TaskNo2.Length == 5)
                            {
                                string[] ss = dal.GetTostation(SrmInfo.TaskNo2, "SC");//查询此时任务号对应的SC起始和SC目标地址
                                if (ss != null)
                                {
                                    SrmInfo.Fromstation2 = ss[0].ToString();
                                    SrmInfo.Tostation2 = ss[1].ToString();
                                    SrmInfo.Barcode2 = ss[2].ToString();
                                    SrmInfo.MESLocation2 = ss[3].ToString();
                                    if (ss[4].ToString() == "0")
                                    {
                                        dal.UpdateTaskStatus(SrmInfo.Fromstation2, SrmInfo.TaskNo2, "", "SC", "2", "1"); //当任务状态未开始时 再次更新任务状态
                                    }
                                }
                                else
                                {
                                    SrmInfo.Fromstation2 = "";
                                    SrmInfo.Tostation2 = "";
                                    SrmInfo.Barcode2 = "";
                                    SrmInfo.MESLocation2 = "";
                                }
                            }
                            bool isOpen = false;
                            string firedoorLocation = string.Empty;
                            //if (scno == "SC01" || scno == "SC02" || scno == "SC03" || scno == "SC04")
                            //{
                            //    firedoorLocation = dal.getFiredoor(scno, ref isOpen);
                            //}
                            if (SrmInfo.FunctionReport == "0")   //空闲
                            {
                                if (isOpen)
                                {
                                    return "空闲状态发现货位消防门打开,堆垛机停止运行,报警货位" + firedoorLocation;
                                }
                                //查询货位是否有火警
                                bool isFire = false;
                                string fireLocation = dal.getFire(scno, ref isFire);
                                if (isFire)//避让
                                {
                                    string avoidPosition = getavoidPosition(scno, SrmInfo.Position, fireLocation);
                                    if (avoidPosition == "")
                                    {
                                        return "空闲状态发现货位有火警,堆垛机已在原点,报警货位" + fireLocation;
                                    }
                                    else
                                    {
                                        if (SrmInfo.TaskNo != "1199")
                                        {
                                            co.BllSrm.SendCode(scno, CR_POS_GET, 1199, avoidPosition, "1");
                                            return "空闲状态发现货位有火警,避让到原点,报警货位" + fireLocation;
                                        }
                                        else
                                            return "已下发火警避让指令";
                                    }
                                }
                            }
                            else if (SrmInfo.FunctionReport == CR_POS_GET_EXECUTED)   //取货前行走完成
                            {
                                if (isOpen)
                                {
                                    return "取货前行走完成发现货位消防门打开,堆垛机停止运行,报警货位" + firedoorLocation;
                                }
                                //查询货位是否有火警
                                bool isFire = false;
                                string fireLocation = dal.getFire(scno, ref isFire);
                                if (isFire)//避让
                                {
                                    string avoidPosition = getavoidPosition(scno, SrmInfo.Position, fireLocation);
                                    if (avoidPosition == "" && SrmInfo.TaskNo == "1199")
                                    {
                                        co.BllSrm.SendCode(scno, CR_NO_FUNC, int.Parse(SrmInfo.TaskNo), "", "0");
                                        return "火警任务,堆垛机已避让至原点,报警货位" + fireLocation;
                                    }
                                    else if (avoidPosition == "")
                                    {
                                        return "取货前行走完成发现货位有火警,堆垛机已在原点,报警货位" + fireLocation;
                                    }
                                    else
                                    {
                                        if (SrmInfo.TaskNo != "1199")
                                        {
                                            co.BllSrm.SendCode(scno, CR_POS_GET, 1199, avoidPosition, "1");
                                            return "取货前行走完成发现货位有火警,避让到原点,报警货位" + fireLocation;
                                        }
                                        else
                                            return "已下发火警避让指令";
                                    }
                                }
                              
                                co.BllSrm.SendCode(scno, CR_NO_FUNC, int.Parse(SrmInfo.TaskNo), "", "0");

                            }
                            else if (SrmInfo.FunctionReport == CR_GETC_POS_RUNNING)   //取货前的移动
                            {
                                if (isOpen)
                                {
                                    co.BllSrm.SendCode(scno, CR_NO_FUNC, int.Parse(SrmInfo.TaskNo), "", "0");
                                    return "取货过程中发现货位消防门打开,堆垛机停止运行,报警货位" + firedoorLocation;
                                }
                                //查询货位是否有火警
                                bool isFire = false;
                                string fireLocation = dal.getFire(scno, ref isFire);
                                if (isFire)//避让
                                {
                                    string avoidPosition = getavoidPosition(scno, SrmInfo.Position, fireLocation);
                                    if (avoidPosition == "")
                                    {
                                        return "取货过程中发现货位有火警,堆垛机已在原点,报警货位" + fireLocation;
                                    }
                                    else
                                    {
                                        if (SrmInfo.TaskNo != "1199")
                                        {
                                            co.BllSrm.SendCode(scno, CR_POS_GET, 1199, avoidPosition, "1");
                                            return "取货过程中发现货位有火警,避让到原点,报警货位" + fireLocation;
                                        }
                                        else
                                            return "已下发火警避让指令";
                                    }
                                }
                            }
                            else if (SrmInfo.FunctionReport == CR_GETC_EXECUTED)   //取货完成
                            {
                                if (isOpen)
                                {
                                    return "取货完成后发现货位消防门打开,堆垛机停止运行,报警货位" + firedoorLocation;
                                }
                                //查询货位是否有火警
                                bool isFire = false;
                                string fireLocation = dal.getFire(scno, ref isFire);
                                if (isFire)//避让
                                {
                                    string avoidPosition = getavoidPosition(scno, SrmInfo.Position, fireLocation);
                                    if (avoidPosition == "")
                                    {
                                        return "取货完成后发现货位有火警,堆垛机已在原点,报警货位" + fireLocation;
                                    }
                                    else
                                    {
                                        if (SrmInfo.TaskNo != "1199")
                                        {
                                            co.BllSrm.SendCode(scno, CR_POS_GET, 1199, avoidPosition, "1");
                                            return "取货完成后发现货位有火警,避让到原点,报警货位:" + fireLocation;
                                        }
                                        else
                                            return "已下发火警避让指令";
                                    }
                                }
                                bool putflag = true;
                                srmLog += "堆垛机取货完成，工位1任务号" + SrmInfo.TaskNo + ",工位2任务号" + SrmInfo.TaskNo2;
                                #region CR_GETC_EXECUTED 取货完成
                                co.BllSrm.WriteLog("S", "堆垛机编号:" + scno + srmLog);
                                if (SrmInfo.ActTU == "1" || SrmInfo.ActTU == "3")
                                {
                                    #region 从扫码货位上取工装后
                                    int count = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Fromstation).ToList().Count();
                                    if (count > 0)
                                    {
                                        string station = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Fromstation).FirstOrDefault().station;
                                        if (string.IsNullOrEmpty(station))
                                        {
                                            return "工装扫码货位:" + SrmInfo.Tostation + "未配置扫码站台!";
                                        }
                                        ConveryBLL converyBLL = new ConveryBLL();
                                        converyBLL.WriteStationInfo(STACommand.ReWrite, new string[6] { station, "0", "0", "0", "0", "0" }, station, 0, 22);
                                    }
                                    #endregion
                                }
                                if (SrmInfo.ActTU == "2" || SrmInfo.ActTU == "3")
                                {
                                    #region 从扫码货位上取工装后
                                    int count = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Fromstation2).ToList().Count();
                                    if (count > 0)
                                    {
                                        string station = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Fromstation2).FirstOrDefault().station;
                                        if (string.IsNullOrEmpty(station))
                                        {
                                            return "工装扫码货位:" + SrmInfo.Tostation + "未配置扫码站台!";
                                        }
                                        ConveryBLL converyBLL = new ConveryBLL();
                                        converyBLL.WriteStationInfo(STACommand.ReWrite, new string[6] { station, "0", "0", "0", "0", "0" }, station, 0, 22);
                                    }
                                    #endregion
                                }
                                if ((SrmInfo.ActTU == "1" && !string.IsNullOrEmpty(SrmInfo.Tostation)) 
                                    || (SrmInfo.ActTU == "2" && !string.IsNullOrEmpty(SrmInfo.Tostation2)) || (SrmInfo.ActTU == "3" && !string.IsNullOrEmpty(SrmInfo.Tostation) && !string.IsNullOrEmpty(SrmInfo.Tostation2)))
                                {
                                    //-------------------------------------------2021-07-6-------林兴煌添加用于发双叉任务--------------------------
                                    if (((SrmInfo.forkStatus2 == 0 && SrmInfo.TaskNo2 == "0" && SrmInfo.TaskNo.Length == 5)
                                        || (SrmInfo.forkStatus1 == 0  && SrmInfo.TaskNo == "0" && SrmInfo.TaskNo2.Length == 5)) && SrmInfo.ActTU != "3" && SrmInfo.ForkType== "forkNo")//货叉1空闲，并且是出库或摆渡任务。因为入库任务，在最开始下发任务的时候已下发。移库任务用单叉移库。
                                    {
                                        string fromstation = SrmInfo.Fromstation;
                                        string tostation = SrmInfo.Tostation;
                                        string sendfromstation = "";
                                        string sendTostation = "";
                                        string taskNo = "";
                                        int fork_number = 2;
                                        if (SrmInfo.ActTU == "2")
                                        {
                                            fork_number = 1;
                                            fromstation = SrmInfo.Fromstation2;
                                            tostation = SrmInfo.Tostation2;
                                        }
                                        if (!SrmInfo.sendFlag)
                                        {  //当没有下发第二次取货任务时  
                                            if (GetOutBoundTaskInfo_Fork(scno, fromstation, tostation, int.Parse(SrmInfo.RackPosition), fork_number.ToString(), ref taskNo, ref sendfromstation, ref sendTostation))
                                            {
                                                if (fork_number == 2)
                                                {
                                                    SrmInfo.TaskNo2 = taskNo;
                                                }
                                                else
                                                {
                                                    SrmInfo.TaskNo = taskNo;
                                                }
                                                if (co.BllSrm.SendTask(scno, SrmInfo.TaskNo, sendfromstation, sendTostation, sendTostation, co.taskType.ToString(), fork_number, Convert.ToInt32(SrmInfo.TaskNo2), sendfromstation, sendTostation, sendTostation))
                                                {// 第二次下发取货指令成功
                                                    putflag = false;
                                                    SrmInfo.sendFlag = true;  //表示下发了第二次取货指令
                                                }
                                            }
                                        }
                                    }
                                    if ((SrmInfo.TaskNo == "0" || SrmInfo.TaskNo2 == "0") && SrmInfo.sendFlag)
                                    {//成功下发了第二次取货指令  但读取到的信息不是最新消息
                                        return "";
                                    }
                                    //-----------------------------------------end-----2021-07-6--------林兴煌添加用于发双叉任务-------------------
                                    if (putflag)
                                    {
                                        int forkNo = 0;
                                        string tostation = "";
                                        //-------------------------------------------2021-07-6-------林兴煌添加用于发双叉任务放货指令--------------------------
                                        SearchForkTaskInfo(SrmInfo, ref forkNo, ref tostation);//无目标地址时候，会转为清空指令
                                        if (forkNo == 1)
                                        {
                                            if (SrmInfo.Tostation.Length > 4)
                                            {
                                                int Column = int.Parse(SrmInfo.Tostation.Substring(4, 3));
                                                if ((SrmInfo.scno == "SC04" && Column == 1 && FaceCode=="B")
                                                    ||((SrmInfo.scno == "SC05" || SrmInfo.scno == "SC06") && Column == 23))
                                                {//B面SC04的第1列  常温静置的第23列  货叉1不可去
                                                    string newTostation = string.Empty;
                                                    //货叉1特殊地址  需要更换为非此列的新货位
                                                    if (SrmInfo.TaskNo.Length == 5)
                                                    {
                                                        if (changTostation(WareHouseID, SrmInfo.scno, SrmInfo.TaskNo, Column, ref newTostation))
                                                        {
                                                            SrmInfo.Tostation = newTostation;
                                                            tostation = newTostation;
                                                        }
                                                        else
                                                        {
                                                            return "堆垛机"+ SrmInfo.scno + ",货叉:"+ forkNo + "不可到" + Column+"列,且该堆垛机无其它列可用货位";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        co.BllSrm.SendCode(scno, CR_PUTC, int.Parse(SrmInfo.TaskNo), tostation, "0", forkNo, int.Parse(SrmInfo.TaskNo2));  //入库时候给货位号，放货指令
                                        SrmInfo.sendFlag = false;
                                        //--------------------------------------end--2021-07-6-------林兴煌添加用于发双叉任务放货指令--------------------------
                                    }
                                }
                                #endregion
                            }
                            else if (SrmInfo.FunctionReport == CR_PUTC_POS_RUNNING)   //放货前的移动
                            {
                                if (isOpen)
                                {
                                    co.BllSrm.SendCode(scno, CR_NO_FUNC, int.Parse(SrmInfo.TaskNo), "", "0");
                                    return "放货移动中发现货位消防门打开,堆垛机停止运行,报警货位" + firedoorLocation;
                                }
                                //查询货位是否有火警
                                bool isFire = false;
                                string fireLocation = dal.getFire(scno, ref isFire);
                                if (isFire)//避让
                                {
                                    string avoidPosition = getavoidPosition(scno, SrmInfo.Position, fireLocation);
                                    if (avoidPosition == "")
                                    {
                                        return "放货移动过程中发现货位有火警,堆垛机已在原点";
                                    }
                                    else
                                    {
                                        if (SrmInfo.TaskNo != "1199")
                                        {
                                            co.BllSrm.SendCode(scno, CR_POS_GET, 1199, avoidPosition, "1");
                                            return "放货移动过程中发现货位有火警,避让到原点"; ;
                                        }
                                        else
                                            return "已下发火警避让指令";
                                    }
                                }
                            }
                            else if (SrmInfo.FunctionReport == CR_PUTC_EXECUTED)  //放货完成 
                            {
                                SrmInfo.sendFlag = false;
                                if (isOpen)
                                {
                                    return "放货完成时发现货位消防门打开,堆垛机停止运行,报警货位" + firedoorLocation;
                                }
                                //查询货位是否有火警
                                bool isFire = false;
                                string fireLocation = dal.getFire(scno, ref isFire);
                                if (isFire)//避让
                                {
                                    string avoidPosition = getavoidPosition(scno, SrmInfo.Position, fireLocation);
                                    if (avoidPosition == "")
                                    {
                                        return "放货完成时发现货位有火警,堆垛机已在原点";
                                    }
                                    else
                                    {
                                        if (SrmInfo.TaskNo != "1199")
                                        {
                                            co.BllSrm.SendCode(scno, CR_POS_GET, 1199, avoidPosition, "1");
                                            return "放货完成时发现货位有火警,避让到原点";
                                        }
                                        else
                                            return "已下发火警避让指令";
                                    }
                                }
                                srmLog += "堆垛机放货完成，工位1任务号" + SrmInfo.TaskNo + ",工位2任务号" + SrmInfo.TaskNo2;

                                #region CR_PUTC_EXECUTED 放货完成
                                if (SrmInfo.TaskNo != null && (SrmInfo.ActTU == "1" || SrmInfo.ActTU == "3"))
                                {
                                    if (SrmInfo.TaskNo.Length > 4)
                                    {
                                        #region 工装扫码
                                        int count = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Tostation).ToList().Count();
                                        if (count > 0)
                                        {
                                            string station = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Tostation).FirstOrDefault().station;
                                            if (string.IsNullOrEmpty(station))
                                            {
                                                return "工装扫码货位:" + SrmInfo.Tostation + "未配置扫码站台!";
                                            }
                                            ConveryBLL converyBLL = new ConveryBLL();
                                            converyBLL.WriteStationInfo(STACommand.ReWrite, new string[6] { station, SrmInfo.TaskNo2, SrmInfo.Barcode2, "2", "0", "9999" }, station, 0, 22);
                                        }
                                        #endregion
                                        dal.UpdateTaskStatus(SrmInfo.Fromstation, SrmInfo.TaskNo, "", "SC", "1", "1");
                                    }
                                    if (SrmInfo.Tostation.Length == 4)
                                    {
                                        ConveryBLL converyBLL = new ConveryBLL();
                                        converyBLL.WriteStationInfo(STACommand.ClearToStation, new string[2] { SrmInfo.Tostation, SrmInfo.Tostation }, SrmInfo.Tostation, 4, 2);
                                    }
                                    SrmInfo.TaskNo = "0";
                                    SrmInfo.Fromstation = "";
                                    SrmInfo.Tostation = "";
                                    SrmInfo.Barcode = "";
                                }
                                if (SrmInfo.TaskNo2 != null && (SrmInfo.ActTU == "2" || SrmInfo.ActTU == "3"))
                                {
                                    if (SrmInfo.TaskNo2.Length > 4)
                                    {
                                        #region 工装扫码
                                        int count = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Tostation2).ToList().Count();
                                        if (count > 0)
                                        {
                                            string station = adjustLocationInfo.Where(x => x.sacnLocationnumber == SrmInfo.Tostation2).FirstOrDefault().station;
                                            if (string.IsNullOrEmpty(station))
                                            {
                                                return "工装扫码货位:" + SrmInfo.Tostation2 + "未配置扫码站台!";
                                            }
                                            ConveryBLL converyBLL = new ConveryBLL();
                                            converyBLL.WriteStationInfo(STACommand.ReWrite, new string[6] { station, SrmInfo.TaskNo2, SrmInfo.Barcode2, "2", "0", "9999" }, station, 0, 22);
                                        }
                                        #endregion
                                        dal.UpdateTaskStatus(SrmInfo.Fromstation2, SrmInfo.TaskNo2, "", "SC", "1", "1");
                                    }
                                    if (SrmInfo.Tostation2.Length == 4)
                                    {
                                        ConveryBLL converyBLL = new ConveryBLL();
                                        converyBLL.WriteStationInfo(STACommand.ClearToStation, new string[2] { SrmInfo.Tostation2, SrmInfo.Tostation2 }, SrmInfo.Tostation2, 4, 2);
                                    }
                                    SrmInfo.TaskNo2 = "0";
                                    SrmInfo.Fromstation2 = "";
                                    SrmInfo.Tostation2 = "";
                                    SrmInfo.Barcode2 = "";
                                }
                                if (SrmInfo.TaskNo2 != null && SrmInfo.TaskNo2.Length >= 4 && SrmInfo.ActTU == "1" && SrmInfo.forkStatus2 == 1)//货叉2有任务，并且有货
                                {
                                    co.BllSrm.SendCode(scno, CR_PUTC, int.Parse(SrmInfo.TaskNo), SrmInfo.Tostation2, "0", 2, int.Parse(SrmInfo.TaskNo2));  //下发放货指令
                                }
                                else if (SrmInfo.TaskNo != null && SrmInfo.TaskNo.Length >= 4 && SrmInfo.ActTU == "2" && SrmInfo.forkStatus1 == 1 )//货叉1有任务，并且有货
                                {
                                    int Column = 0;
                                    if (SrmInfo.Tostation.Length >4)
                                    {
                                        Column = int.Parse(SrmInfo.Tostation.Substring(4, 3));
                                    }
                                    if ((SrmInfo.scno == "SC04" && Column == 1 && FaceCode == "B")
                                        || ((SrmInfo.scno == "SC05" || SrmInfo.scno == "SC06") && Column == 23))
                                    {//B面SC04的第1列  常温静置的第23列  货叉1不可去
                                        string newTostation = string.Empty;
                                        //货叉1特殊地址  需要更换为非此列的新货位
                                        if (SrmInfo.TaskNo.Length == 5)
                                        {
                                            string tostation = "";
                                            if (changTostation(WareHouseID, SrmInfo.scno, SrmInfo.TaskNo, Column, ref newTostation))
                                            {
                                                SrmInfo.Tostation = newTostation;
                                                tostation = newTostation;
                                            }
                                            else
                                            {
                                                return "堆垛机" + SrmInfo.scno + ",货叉1不可到" + Column + "列,且该堆垛机无其它列可用货位";
                                            }
                                        }
                                    }
                                    co.BllSrm.SendCode(scno, CR_PUTC, int.Parse(SrmInfo.TaskNo), SrmInfo.Tostation, "0", 1, int.Parse(SrmInfo.TaskNo2));  //下发放货指令
                                }
                                else
                                {
                                    SrmInfo.Fromstation = "";
                                    SrmInfo.Tostation = "";
                                    SrmInfo.Fromstation2 = "";
                                    SrmInfo.Tostation2 = "";
                                    co.BllSrm.SendCode(scno, CR_NO_FUNC, 0, "", "0");
                                }
                                co.BllSrm.WriteLog("S", "堆垛机编号:" + scno + srmLog);
                                #endregion
                            }
                        }
                    }
                    else
                    {
                        return "";
                    }
                    #endregion
                }
            }
            return srmLog;
        }
        public static string RemoveNotNumber(string key)
        {
            return Regex.Replace(key, @"[^\d]*", "");
        }
        /// <summary>
        /// 根据任务信息，查询出双叉信息，同时根据工位更新输送机、堆垛机任务的取货地址与目标地址
        /// </summary>
        /// <param name="wcs_SubtaskInfo_list">可下发任务列表</param>
        /// <param name="fromstation">传入起始地址</param>
        /// <param name="tostation">传入目标地址</param>
        /// <param name="taskNo">传入任务号</param>
        /// <param name="barcode">传入托盘条码</param>
        /// <param name="forkNo">反馈当前执行货叉几的任务--1：货叉1--2：货叉2--3：同时取</param>
        /// <param name="taskFork1">反馈货叉1的任务信息</param>
        /// <param name="taskFork2">货叉2的信息反馈</param>
        /// <returns>true取taskFork1、taskFork2值，false根据forkNo值取相应taskFork1、taskFork2信息 </returns>
        public bool SearchForkTaskInfo(CRCStatus SrmInfo, ref int forkNo, ref string tostation)
        {
            forkNo = 0;
            tostation = "";
            string tostationFork1 = SrmInfo.Tostation;//货叉1目标地址
            string tostationFork2 = SrmInfo.Tostation2;//货叉2目标地址
            #region 任务为单叉任务
            if (SrmInfo.TaskNo2 == "0" && SrmInfo.forkStatus2 == 0 && SrmInfo.TaskNo != "0" && SrmInfo.forkStatus1 != 0 )//该任务为货叉1单叉任务
            {
                tostation = SrmInfo.Tostation;
                forkNo = 1;
                return true;
            }
            if (SrmInfo.TaskNo == "0" && SrmInfo.forkStatus1 == 0 && SrmInfo.TaskNo2 != "0" && SrmInfo.forkStatus2 != 0 )//.该任务为货叉2单叉任务
            {
                tostation = SrmInfo.Tostation2;
                forkNo = 2;
                return true;
            }
            if (string.IsNullOrEmpty(tostationFork1) && !string.IsNullOrEmpty(tostationFork2))
            {
                tostation = SrmInfo.Tostation2;
                forkNo = 2;
                return true;

            }
            else if (!string.IsNullOrEmpty(tostationFork1) && string.IsNullOrEmpty(tostationFork2))
            {
                tostation = SrmInfo.Tostation;
                forkNo = 1;
                return true;
            }
            else if (string.IsNullOrEmpty(tostationFork1) && string.IsNullOrEmpty(tostationFork2))//两个货叉的任务目标地址都为空，报错
            {
                forkNo = 0;
                return false;
            }
            #endregion
            #region 任务为双叉任务
            #region 出库任务
            if (SrmInfo.Fromstation.Length > SrmInfo.Tostation.Length)//出库任务，默认以货叉1为取放点下发出库任务
            {
                tostation = SrmInfo.Tostation;
                forkNo = 3;
                return true;
            }
            #endregion
            #region//入库任务，需要处理输送机站台工位1与工位2，位置关系
            if (SrmInfo.Fromstation.Length < SrmInfo.Tostation.Length)//入库任务，需要处理相邻的库位托盘。
            {
                string destAdress = RemoveNotNumber(SrmInfo.Tostation); //S0010010011   
                string destAdress2 = RemoveNotNumber(SrmInfo.Tostation2); //S0010010011   
                int row = int.Parse(destAdress.Substring(0, 3)) % 2 == 0 ? 2 : 1;
                int Column = int.Parse(destAdress.Substring(3, 3));
                int layer = int.Parse(destAdress.Substring(6, 3));
                int row1 = int.Parse(destAdress2.Substring(0, 3)) % 2 == 0 ? 2 : 1;
                int Column1 = int.Parse(destAdress2.Substring(3, 3));
                int layer1 = int.Parse(destAdress2.Substring(6, 3));
                if (FaceCode == "B") //B面
                {
                    // SC02堆垛机1排19/20  2排9/10  19/20不可同时取放
                    if (SrmInfo.scno == "SC02" && (row == 1 && (Column == 19 && Column1 == 20)) ||
                        (row == 2 && ((Column == 9 && Column1 == 10) || (Column == 19 && Column1 == 20))))
                    {
                        tostation = SrmInfo.Tostation;
                        forkNo = 1;
                        return true;
                    }
                    // SC04堆垛机1排10/11  2排10/11  20/21不可同时取放
                    if (SrmInfo.scno == "SC04" && (row == 1 && (Column1 == 10 && Column == 11)) ||
                       (row == 2 && ((Column1 == 10 && Column == 11) || (Column1 == 20 && Column == 21))))
                    {
                        tostation = SrmInfo.Tostation;
                        forkNo = 1;
                        return true;
                    }
                }
                if (FaceCode == "A") //A面
                {
                    // SC02堆垛机2排9/10  1排9/10  19/20不可同时取放
                    if (SrmInfo.scno == "SC02" && (row == 2 && (Column == 9 && Column1 == 10)) ||
                        (row == 1 && ((Column == 9 && Column1 == 10) || (Column == 19 && Column1 == 20))))
                    {
                        tostation = SrmInfo.Tostation;
                        forkNo = 1;
                        return true;
                    }
                    // SC04堆垛机2排18/19  1排8/9  18/19不可同时取放
                    if (SrmInfo.scno == "SC04" && (row == 2 && (Column1 == 18 && Column == 19)) ||
                       (row == 2 && ((Column1 == 8 && Column == 9) || (Column1 == 18 && Column == 19))))
                    {
                        tostation = SrmInfo.Tostation;
                        forkNo = 1;
                        return true;
                    }
                }
                if (SrmInfo.scno == "SC01" || SrmInfo.scno == "SC03")
                {
                    tostation = SrmInfo.Tostation;
                    forkNo = 1;
                    return true;
                }
                // SC05/SC06堆垛机  2/3不可同时取放
                if ((SrmInfo.scno == "SC05" || SrmInfo.scno == "SC06") && (Column == 2 && Column1 == 3))
                {
                    tostation = SrmInfo.Tostation;
                    forkNo = 1;
                    return false;
                }
                //相邻货位
                if (row1 == row && layer == layer1 && Math.Abs(Column - Column1) == 1)
                {
                    if (SrmInfo.scno == "SC04")
                    {
                        if (Column - Column1 == 1)
                        {
                            forkNo = 3;//可同时取货。
                        }
                        else
                        {
                            forkNo = 1;
                        }
                        tostation = SrmInfo.Tostation;//货位定位以货叉1为准
                        return true;
                    }
                    else
                    {
                        if (Column1 - Column == 1)
                        {
                            forkNo = 3;//可同时取货。
                        }
                        else
                        {
                            forkNo = 1;
                        }
                        tostation = SrmInfo.Tostation;//货位定位以货叉1为准
                        return true;
                    }
                }
                else //货位不相邻意味着要先放一托盘 根据地址判断哪个货叉先放 减少堆垛机重复移动
                {
                    if (SrmInfo.scno == "SC01")
                    {
                        if (SrmInfo.Fromstation == "1427" || SrmInfo.Fromstation == "1428" || SrmInfo.Fromstation == "1724" || SrmInfo.Fromstation == "1726")
                        {
                            forkNo = Column > Column1 ? 1 : 2;
                            tostation = Column > Column1 ? SrmInfo.Tostation : SrmInfo.Tostation2; //优先发送大列
                            return false;
                        }
                        else
                        {
                            forkNo = Column > Column1 ? 2 : 1;
                            tostation = Column > Column1 ? SrmInfo.Tostation2 : SrmInfo.Tostation; //优先发送小列
                            return false;
                        }
                    }
                    if (SrmInfo.scno == "SC02")
                    {
                        if (SrmInfo.Fromstation == "1033" || SrmInfo.Fromstation == "1035" || SrmInfo.Fromstation == "1405" || SrmInfo.Fromstation == "1407")
                        {
                            forkNo = Column > Column1 ? 2 : 1;
                            tostation = Column > Column1 ? SrmInfo.Tostation2 : SrmInfo.Tostation; //优先发送小列
                            return false;
                        }
                        else
                        {
                            forkNo = Column > Column1 ? 1 : 2;
                            tostation = Column > Column1 ? SrmInfo.Tostation : SrmInfo.Tostation2; //优先发送大列
                            return false;
                        }
                    }
                    if (SrmInfo.scno == "SC03")
                    {
                        if (SrmInfo.Fromstation == "1497" || SrmInfo.Fromstation == "1499")
                        {
                            forkNo = Column > Column1 ? 1 : 2;
                            tostation = Column > Column1 ? SrmInfo.Tostation : SrmInfo.Tostation2; //优先发送大列
                            return false;
                        }
                        else
                        {
                            forkNo = Column > Column1 ? 2 : 1;
                            tostation = Column > Column1 ? SrmInfo.Tostation2 : SrmInfo.Tostation; //优先发送小列
                            return false;
                        }
                    }
                    if (SrmInfo.scno == "SC04")
                    {
                        if (SrmInfo.Fromstation == "1445" || SrmInfo.Fromstation == "1447")
                        {
                            forkNo = Column > Column1 ? 2 : 1;
                            tostation = Column > Column1 ? SrmInfo.Tostation2 : SrmInfo.Tostation; //优先发送小列
                            return false;
                        }
                        else
                        {
                            forkNo = Column > Column1 ? 1 : 2;
                            tostation = Column > Column1 ? SrmInfo.Tostation : SrmInfo.Tostation2; //优先发送大列
                            return false;
                        }
                    }
                    if (SrmInfo.scno == "SC05" || SrmInfo.scno == "SC06")
                    {
                        if (SrmInfo.Fromstation == "1187" || SrmInfo.Fromstation == "1189" || SrmInfo.Fromstation == "1198" || SrmInfo.Fromstation == "1200")
                        {
                            forkNo = Column > Column1 ? 1 : 2;
                            tostation = Column > Column1 ? SrmInfo.Tostation : SrmInfo.Tostation2; //优先发送大列
                            return false;
                        }
                        else
                        {
                            forkNo = Column > Column1 ? 2 : 1;
                            tostation = Column > Column1 ? SrmInfo.Tostation2 : SrmInfo.Tostation; //优先发送小列
                            return false;
                        }
                    }
                }
            }
            #endregion
            #region//移库任务
            if (SrmInfo.Fromstation.Length == SrmInfo.Tostation.Length)//移库库任务，默认以货叉1为取放点下发移库任务
            {
                tostation = SrmInfo.Tostation;
                forkNo = 3;
                return true;
            }
            #endregion
            #endregion
            return false;//若无双叉任务，默认将传进来的任务单叉下发。同时告知下发货叉1还是货叉2。
        }
        /// <summary>
        /// 获取空闲货叉的任务信息。
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="msg"></param>
        private bool GetOutBoundTaskInfo_Fork(string SCNO, string sc_fromstation, string sc_tostation, int b_I_Row, string fork_number, ref string checkTaskNo, ref string sendFromstation, ref string sendTostation)
        {
            DataSet ds = dal.GetTaskByEquipmentnumber(SCNO);   //;//获取任务
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                string workNo1tostation = ""; //空闲货叉的工位
                string workNo1fromstation = ""; //空闲货叉的工位
                Dictionary<string, string> dic = new Dictionary<string, string>();
                if (dt.Rows.Count > 0)
                {
                    int maxcolumn = 0;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string fromstation = dt.Rows[i]["fromstation"].ToString().Trim();
                        string tostation = dt.Rows[i]["tostation"].ToString().Trim();
                        if (fromstation.Length == 5)
                        {
                            dt.Rows[i]["curpostion"] = Math.Abs(b_I_Row - maxcolumn);//"F0030010011"
                        }
                        else if (fromstation.Length > 5)
                        {
                            dt.Rows[i]["curpostion"] = Math.Abs(b_I_Row - int.Parse(fromstation.Substring(3, 3)));
                        }
                    }
                }
                else
                {
                    return false;
                }
                if (converyZoneInfo.Exists(x => (x.stationNo == x.WORKINGLOCATION1 || x.stationNo == x.WORKINGLOCATION2) && !string.IsNullOrEmpty(x.WORKINGLOCATION1) && !string.IsNullOrEmpty(x.WORKINGLOCATION2)))
                {
                    foreach (DataRow row in dt.Select(" 1=1 ", "priority desc,createtime,curpostion ,taskno"))
                    {
                        if (dic.ContainsKey(row["taskno"].ToString().Trim() + "-" + row["barcode"].ToString().Trim()))
                            continue;
                        string taskno = row["taskno"].ToString().Trim();
                        string fromstation = row["fromstation"].ToString().Trim();
                        string tostation = row["tostation"].ToString().Trim();
                        string barcode = row["barcode"].ToString().Trim();
                        if (fromstation == sc_fromstation && tostation == sc_tostation) continue;
                        if (fromstation.Length != sc_fromstation.Length || tostation.Length != sc_tostation.Length) continue;//与货叉1不一致的任务任务类型，都过滤掉                        
                        if (sc_fromstation.Length > sc_tostation.Length)//出库任务
                        {
                            if (fork_number == "1")
                                workNo1tostation = converyZoneInfo.Where(x => x.stationNo == sc_tostation).FirstOrDefault().WORKINGLOCATION1;//工位1
                            else
                                workNo1tostation = converyZoneInfo.Where(x => x.stationNo == sc_tostation).FirstOrDefault().WORKINGLOCATION2;//工位2

                            if (tostation != sc_tostation && workNo1tostation != tostation) continue;//屏蔽不是同一个出库口的任务
                            if (SCNO == "SC04" && fork_number == "1" && int.Parse(fromstation.Substring(4, 3)) == 1 && FaceCode=="B") continue;  //B面4号堆垛机当1号货叉空闲时 屏蔽第1列任务
                            if ((SCNO == "SC05" || SCNO == "SC06") && fork_number == "1" && int.Parse(fromstation.Substring(4, 3)) == 23) continue;  //5,6号堆垛机当1号货叉空闲时 屏蔽第22列任务   
                            checkTaskNo = CheckStation(fromstation, workNo1tostation, taskno);
                            if (checkTaskNo == taskno)
                            {
                                if (UpdateTaskStation(barcode, taskno, tostation, workNo1tostation))//更新另一个货叉的目标地址
                                {
                                    sendFromstation = fromstation;
                                    sendTostation = tostation;
                                    return true;
                                }
                            }
                        }
                        if (sc_tostation.Length > sc_fromstation.Length)//入库任务
                        {
                            if (fork_number == "1")
                                workNo1fromstation = converyZoneInfo.Where(x => x.stationNo == sc_fromstation).FirstOrDefault().WORKINGLOCATION1;//工位1
                            else
                                workNo1fromstation = converyZoneInfo.Where(x => x.stationNo == sc_fromstation).FirstOrDefault().WORKINGLOCATION2;//工位2

                            if (fromstation != sc_fromstation && workNo1fromstation != fromstation) continue;//屏蔽不是同一个入库口的任务
                            if (SCNO == "SC04" && fork_number == "1" && int.Parse(tostation.Substring(4, 3)) == 1 && FaceCode=="B") continue;  //B面4号堆垛机当1号货叉空闲时 屏蔽第1列任务
                            if ((SCNO == "SC05" || SCNO == "SC06") && fork_number == "1" && int.Parse(tostation.Substring(4, 3)) == 23) continue;  //5,6号堆垛机当1号货叉空闲时 屏蔽第23列任务   
                            checkTaskNo = CheckStation(workNo1fromstation, tostation, taskno);
                            if (checkTaskNo == taskno)
                            {
                                sendFromstation = fromstation;
                                sendTostation = tostation;
                                return true;
                            }
                        }
                        if (sc_tostation.Length == sc_fromstation.Length && sc_tostation.Length == 4)//摆渡任务
                        {
                            if (fork_number == "1")
                            {
                                workNo1tostation = converyZoneInfo.Where(x => x.stationNo == sc_tostation).FirstOrDefault().WORKINGLOCATION1;//工位1
                                workNo1fromstation = converyZoneInfo.Where(x => x.stationNo == sc_fromstation).FirstOrDefault().WORKINGLOCATION1;//工位1
                            }
                            else
                            {
                                workNo1tostation = converyZoneInfo.Where(x => x.stationNo == sc_tostation).FirstOrDefault().WORKINGLOCATION2;//工位2
                                workNo1fromstation = converyZoneInfo.Where(x => x.stationNo == sc_fromstation).FirstOrDefault().WORKINGLOCATION2;//工位2
                            }

                            if (fromstation != sc_fromstation && workNo1fromstation != fromstation) continue;//屏蔽不是同一个入库口的任务
                            if (tostation != sc_tostation && workNo1tostation != tostation) continue;//屏蔽不是同一个出库口的任务

                            checkTaskNo = CheckStation(workNo1fromstation, tostation, taskno);

                            if (checkTaskNo == taskno)
                            {
                                checkTaskNo = CheckStation(fromstation, workNo1tostation, taskno);
                                if (checkTaskNo == taskno)
                                {
                                    sendFromstation = fromstation;
                                    sendTostation = tostation;
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
        /// <summary>
        /// 获取输送机站台区域表
        /// </summary>
        public void GetConveryZoneInfo()
        {
            if (converyZoneInfo.Count == 0)
            {
                DataSet opcitemInfo = dal.GetOpcitemInfo();
                if (!(opcitemInfo.Tables[0].Rows.Count > 0))
                {
                    return;
                }
                DataTable getOpcitemInfo = opcitemInfo.Tables[0];
                if (getOpcitemInfo.Rows.Count > 0)
                {
                    for (int i = 0; i < getOpcitemInfo.Rows.Count; i++)
                    {
                        ConveryZoneInfo _converyZoneInfo = new ConveryZoneInfo();
                        _converyZoneInfo.stationNo = getOpcitemInfo.Rows[i]["itemid"].ToString();
                        _converyZoneInfo.AGVzone = getOpcitemInfo.Rows[i]["zone"].ToString();
                        _converyZoneInfo.WORKINGLOCATION1 = getOpcitemInfo.Rows[i]["workingLocation1"].ToString();
                        _converyZoneInfo.WORKINGLOCATION2 = getOpcitemInfo.Rows[i]["workingLocation2"].ToString();
                        _converyZoneInfo.waitLeaveStation = getOpcitemInfo.Rows[i]["workingNumber"].ToString();
                        converyZoneInfo.Add(_converyZoneInfo);
                    }
                }
            }
        }
        public void GetAdjustScan()
        {
            if (adjustLocationInfo.Count == 0)
            {
                DataSet adjustInfo = dal.GetAdjustInfo();
                if (!(adjustInfo.Tables[0].Rows.Count > 0))
                {
                    return;
                }
                DataTable getAdjustInfo = adjustInfo.Tables[0];
                if (getAdjustInfo.Rows.Count > 0)
                {
                    for (int i = 0; i < getAdjustInfo.Rows.Count; i++)
                    {
                        AdjustLocation adjustLocation  = new AdjustLocation();
                        adjustLocation.adjustLocationnumber = getAdjustInfo.Rows[i]["adjustLocationnumber"].ToString();
                        adjustLocation.sacnLocationnumber = getAdjustInfo.Rows[i]["scanLocationnumber"].ToString();
                        adjustLocation.station = getAdjustInfo.Rows[i]["station"].ToString();
                        adjustLocationInfo.Add(adjustLocation);
                    }
                }
            }
        }
        public string GetAlarmInfo(string num, string alarm, bool update)
        {
            CRCStatus css = list_srm_info.Find(
                delegate (CRCStatus info)
                {
                    return info.scno == num;
                }
            );
            if (css == null)
            {
                return "";
            }
            if (update)
            {
                css.AlarmInfo = alarm;

                return alarm;
            }
            else
            {
                string stralarm = "", changealarm = "";
                if (!System.String.IsNullOrEmpty(css.AlarmInfo))
                {
                    string[] msg = css.AlarmInfo.Split(new char[] { ';' });
                    for (int i = 0; i < msg.Length; i++)
                    {
                        if (msg[i] != "" && msg[i] != "0")
                        {
                            string index = msg[i].Substring(0, msg[i].IndexOf(':'));
                            string ala = msg[i].Substring(msg[i].IndexOf(':') + 1, msg[i].Length - msg[i].IndexOf(':') - 1);
                            int[] alarmbit = FunctionMode(int.Parse(ala));
                            for (int j = 0; j < alarmbit.Length; j++)
                            {
                                if (alarmbit[j] == 1)
                                {
                                    foreach (DictionaryEntry de in AlarmHash)
                                    {
                                        if (de.Key.ToString() == css.scno.Substring(0, 1) + index + "." + j.ToString())
                                        {
                                            stralarm += de.Value.ToString() + ";\r\n";
                                            changealarm += index + "." + j.ToString() + ";";
                                        }
                                    }
                                }
                            }

                        }
                    }
                    //for (int k = 0; k < (stralarm.Length - 1) / 15; k++)
                    //{
                    //    stralarm = stralarm.Insert((k + 1) * 15, ".");
                    //}

                }
                return stralarm;
            }

        }
        public string getavoidPosition(string scno, string scPostion, string fireLocaion)
        {
            string avoidPostion = string.Empty;
            if (scPostion.Length == 4)
            {
                if (scno == "SC01")
                {
                    if (scPostion == "1039" && Int32.Parse(fireLocaion.Substring(4, 3)) == 1)
                    {
                        avoidPostion = "1050";
                    }
                    else if (scPostion == "1050" || scPostion == "1428" || scPostion == "1726" && Int32.Parse(fireLocaion.Substring(4, 3)) == 14)
                    {
                        avoidPostion = "1039";
                    }
                    else
                        avoidPostion = "";
                }
                if (scno == "SC02")
                {
                    if (scPostion == "1035" || scPostion == "1407" || scPostion == "1702" && Int32.Parse(fireLocaion.Substring(4, 3)) == 1)
                    {
                        avoidPostion = "1035";
                    }

                    else if (scPostion == "1081" || scPostion == "1418" && Int32.Parse(fireLocaion.Substring(4, 3)) == 24)
                    {
                        avoidPostion = "1039";
                    }
                    else
                        avoidPostion = "";
                }
                if (scno == "SC03")
                {
                    if (scPostion == "1127" || scPostion == "1499" && Int32.Parse(fireLocaion.Substring(4, 3)) == 1)
                    {
                        avoidPostion = "1093";
                    }
                    else if (scPostion == "1093" || scPostion == "1438"&& Int32.Parse(fireLocaion.Substring(4, 3)) == 14)
                    {
                        avoidPostion = "1039";
                    }
                    else
                        avoidPostion = "";
                }
                if (scno == "SC04")
                {
                    if (scPostion == "1102" || scPostion == "1509" || scPostion == "1763" && Int32.Parse(fireLocaion.Substring(4, 3)) == 1)
                    {
                        avoidPostion = "1091";
                    }
                    else if (scPostion == "1091" || scPostion == "1447" && Int32.Parse(fireLocaion.Substring(4, 3)) == 29)
                    {
                        avoidPostion = "1039";
                    }
                    else
                        avoidPostion = "";
                }
                if (scno == "SC05")
                {
                    if (scPostion == "1189" || scPostion == "1523" && Int32.Parse(fireLocaion.Substring(4, 3)) == 1)
                    {
                        avoidPostion = "1469";
                    }
                    else if (scPostion == "1146" || scPostion == "1155" || scPostion == "1482" || scPostion == "1469" || scPostion == "1738" && Int32.Parse(fireLocaion.Substring(4, 3)) == 29)
                    {
                        avoidPostion = "1523";
                    }
                    else
                        avoidPostion = "";
                }
                if (scno == "SC06")
                {
                    if (scPostion == "1200" || scPostion == "1513" && Int32.Parse(fireLocaion.Substring(4, 3)) == 1)
                    {
                        avoidPostion = "1465";
                    }
                    else if (scPostion == "1163" || scPostion == "1172" || scPostion == "1465" || scPostion == "1449" || scPostion == "1728" && Int32.Parse(fireLocaion.Substring(4, 3)) == 29)
                    {
                        avoidPostion = "1513";
                    }
                    else
                        avoidPostion = "";
                }
            }
            else
            {
                int scPostionColum = Int32.Parse(scPostion.Substring(4, 3));
                int fireLocaionColum = Int32.Parse(fireLocaion.Substring(4, 3));
                if (scno == "SC01")
                {
                    if (scPostionColum >= fireLocaionColum)
                    {
                        avoidPostion = "1050";
                    }
                    else
                    {
                        avoidPostion = "1039";
                    }
                }
                else if (scno == "SC02")
                {
                    if (scPostionColum >= fireLocaionColum)
                    {
                        avoidPostion = "1081";
                    }
                    else
                    {
                        avoidPostion = "1035";
                    }
                }
                else if (scno == "SC03")
                {
                    if (scPostionColum >= fireLocaionColum)
                    {
                        avoidPostion = "1127";
                    }
                    else
                    {
                        avoidPostion = "1093";
                    }
                }
                else if (scno == "SC04")
                {
                    if (scPostionColum >= fireLocaionColum)
                    {
                        avoidPostion = "1509";
                    }
                    else
                    {
                        avoidPostion = "1447";
                    }
                }
                else if (scno == "SC05")
                {
                    if (scPostionColum >= fireLocaionColum)
                    {
                        avoidPostion = "1189";
                    }
                    else
                    {
                        avoidPostion = "1155";
                    }
                }
                else if (scno == "SC06")
                {
                    if (scPostionColum >= fireLocaionColum)
                    {
                        avoidPostion = "1200";
                    }
                    else
                    {
                        avoidPostion = "1163";
                    }
                }
            }
            return avoidPostion;
        }
        //堆垛机号,起始地址，目标地址，输送机目标地址，任务类型；
        public bool UpdateCRCTaskInfo(string scno, string fromstation, string tostation, string statostation, string tasktype, int forkNo = 1, string fromstation1 = "", string tostation1 = "", string statostation1 = "")
        {
            CRCStatus SrmInfo = list_srm_info.Find(
                delegate (CRCStatus info)
                {
                    return info.scno == scno;
                }
            );
            if (SrmInfo != null)
            {
                if (forkNo == 1)
                {
                    SrmInfo.Fromstation = fromstation;
                    SrmInfo.Tostation = tostation;
                    if (statostation.Length == 4)
                    {
                        SrmInfo.STAToStation = statostation;
                    }
                    else
                    {
                        SrmInfo.STAToStation = "";
                    }
                }
                if (forkNo == 2)
                {
                    SrmInfo.Fromstation2 = fromstation1;
                    SrmInfo.Tostation2 = tostation1;
                    if (statostation.Length == 4)
                    {
                        SrmInfo.STAToStation2 = statostation1;
                    }
                    else
                    {
                        SrmInfo.STAToStation2 = "";
                    }
                }
                if (forkNo == 3)
                {
                    SrmInfo.Fromstation = fromstation;
                    SrmInfo.Tostation = tostation;
                    SrmInfo.Fromstation2 = fromstation1;
                    SrmInfo.Tostation2 = tostation1;
                    if (statostation.Length == 4)
                    {
                        SrmInfo.STAToStation2 = statostation1;
                    }
                    else
                    {
                        SrmInfo.STAToStation2 = "";
                    }
                }
                SrmInfo.TaskType = tasktype;
                return true;
            }
            return false;
        }

        //p1巷道号    P2是rackside  p3是列值 p4是1（货格） P5是高度层值  p6是1深度
        private string GetLocation(string num, int p1, int p2, int p3, int p4, int p5, int p6)
        {
            string str = "";
            if (p1 == 1)
            {
                int row = p2 == 0 ? 0 : p2 % 2 == 0 ? 2 : 1;
                str += "A" + row.ToString().PadLeft(3, '0');
                str += p3.ToString().PadLeft(3, '0');
                //str += p4.ToString();
                str += p5.ToString().PadLeft(3, '0') + (p6 == 0 ? 1 : p6);
                return str;
            }
            else
            {
                if (num == "SC01")
                {
                    switch (p1)
                    {
                        //sc1
                        case 2: str = "1039"; break;  //二层出库
                        case 3: str = "1050"; break;  //入库取货
                        case 4: str = "1428"; break;  //出库放货有死挡
                        case 5: str = "1726"; break;  //出库放货无死挡
                    }
                }
                else if (num == "SC02")
                {
                    switch (p1)
                    {
                        case 2: str = "1035"; break;  //二层出库
                        case 3: str = "1407"; break;  //入库取货
                        case 4: str = "1702"; break;  //出库放货有死挡
                        case 5: str = "1081"; break;  //出库放货无死挡
                        case 6: str = "1418"; break;  //出库放货无死挡
                    }
                }
                else if (num == "SC03")
                {
                    switch (p1)
                    {
                        case 2: str = "1093"; break;  //二层出库
                        case 3: str = "1438"; break;  //入库取货
                        case 4: str = "1127"; break;  //出库放货有死挡
                        case 5: str = "1499"; break;  //出库放货无死挡
                    }
                }
                else if (num == "SC04")
                {
                    switch (p1)
                    {
                        case 2: str = "1091"; break;  //二层出库
                        case 3: str = "1447"; break;  //入库取货
                        case 4: str = "1102"; break;  //出库放货有死挡
                        case 5: str = "1509"; break;  //出库放货无死挡
                        case 6: str = "1763"; break;  //出库放货无死挡
                    }
                }
                else if (num == "SC05")
                {
                    switch (p1)
                    {
                        case 2: str = "1146"; break;  //二层出库
                        case 3: str = "1155"; break;  //入库取货
                        case 4: str = "1482"; break;  //出库放货有死挡
                        case 5: str = "1469"; break;  //出库放货无死挡
                        case 6: str = "1738"; break;  //出库放货无死挡
                        case 7: str = "1189"; break;  //出库放货有死挡
                        case 8: str = "1523"; break;  //出库放货无死挡
                    }
                }
                else if (num == "SC06")
                {
                    switch (p1)
                    {
                        case 2: str = "1163"; break;  //二层出库
                        case 3: str = "1172"; break;  //入库取货
                        case 4: str = "1465"; break;  //出库放货有死挡
                        case 5: str = "1449"; break;  //出库放货无死挡
                        case 6: str = "1728"; break;  //入库取货
                        case 7: str = "1200"; break;  //出库放货有死挡
                        case 8: str = "1513"; break;  //出库放货无死挡
                    }
                }
                return str;
            }
        }

        // 获取堆垛机模式：自动(半自动、手动),故障,正常：就绪：远程(本地、报警）
        public int[] FunctionMode(int checkinfo)
        {
            string errorcode = Convert.ToString(checkinfo, 2);
            Int32 length = errorcode.Length;
            int[] ErrorCode = new int[8];
            for (int i = length - 1; i >= 0; i--)
            {
                ErrorCode[length - i - 1] = int.Parse(errorcode.Substring(i, 1).ToString());
            }
            return ErrorCode;
        }

        public string GetFunctionMode(int[] functionmode, int[] cranemode)
        {
            string mode = (functionmode[0] == 1 ? "自动;" : "");
            mode += (functionmode[1] == 1 ? "半自动;" : "");
            mode += (functionmode[2] == 1 ? "手动;" : "");
            mode += (functionmode[3] == 1 ? "软停;" : "");//人工停止模式，先执行完当前任务，后面不下发
            mode += (functionmode[4] == 1 ? "就绪;" : "");


            mode += (functionmode[7] == 1 ? "故障;" : "正常;");
            //if (cranemode[0] == 1)
            //    mode += "远程;";
            //if (cranemode[1] == 1)
            //    mode += "本地;";
            //if (cranemode[7] == 1)
            //    mode += "报警;";
            return mode;
        }

        public string GetTaskStatusBase(string code, string codeh)
        {
            #region
            switch (code)
            {
                case "0": return "空闲";//CR_NO_FUNC 
                case "16": return "等待取货";//CR_POS_GET_WAIT_H
                case "17": return "定位动作执行中";//CR_POS_GET_RUNNING
                case "25": return "取货行走完成";//取货完成CR_POS_GET_EXECUTED
                case "26": return "定位动作执行失败";//CR_POS_GET_FAILED
                case "27": return "定位动作被操作员中断";//CR_POS_GET_ABORTED 
                case "32": return "等待故障处理";// CR_GET_WAIT_H
                case "33": return "取货动作执行中"; //CR_GET_RUNNING
                case "41": return "取货动作完成";
                case "42": return "取货动作失败";
                case "43": return "取货动作被操作员中断";
                case "44": return "物流故障导致取货动作中断";
                case "45": return "货位为空导致取货动作中断";
                case "46": return "目标货位无法到达导致取货动作中断";
                case "48": return "等待故障处理";
                case "49": return "定位动作执行中";
                case "57": return "定位动作完成";
                case "58": return "定位动作执行失败";
                case "59": return "定位动作被操作员中断";
                case "64": return "等待故障处理";
                case "65": return "放货动作执行中";
                case "73": return "放货动作完成";
                case "74": return "放货动作失败";
                case "75": return "放货动作被操作员中断";
                case "76": return "物流故障导致放货动作中断";
                case "77": return "货位被占用导致放货动作中断";
                case "78": return "目标货位无法到达导致放货动作中断";
                case "112": return "取货|等待故障处理";
                case "113": return "取货运行中";//取货运行中
                case "114": return "取货动作执行中";//取货伸叉
                case "121": return "取货完成";//取货完成
                case "122": return "取货失败";//取货失败
                case "123": return "取货中止";//取货中止
                case "124": return "物流故障导致GETC动作中断";//
                case "125": return "货位为空导致GETC动作中断";
                case "126": return "目标货位无法到达导致GETC动作中断";

                case "128": return "放货|等待故障处理";
                case "129": return "放货|定位动作执行中";
                case "130": return "放货动作执行中";
                case "137": return "放货完成";
                case "138": return "放货完成失败";
                case "139": return "放货动作中断";
                case "140": return "输送线故障导致放货中断";
                case "141": return "货位为空导致放货动作中断";
                case "142": return "放货时目标货位有货";
                default: return "";
            }
            #endregion
        }

        public CRCObject GetCRCObject(string srmno)
        {
            CRCObject cco = list_srm_object.Find(
                               delegate (CRCObject c)
                               {
                                   return c.ScNo == srmno;
                               }
                           );
            return cco;
        }
        /// <summary>
        /// 获取堆垛机状态
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public string[] GetCRCStatus(string num)
        {
            string[] ret = new string[19] { "", "", "0", "", "", "", "0", "0", "0", "", "0", "0", "0", "0", "0", "", "0", "", "" };
            CRCStatus css = list_srm_info.Find(
                delegate (CRCStatus info)
                {
                    return info.scno == num;
                }
            );
            if (css != null)
            {
                ret[0] = css.Position;
                ret[1] = css.FunctionReport;
                ret[2] = css.FunctionMode;
                ret[3] = css.TaskNo;
                ret[6] = css.AisleNumber;
                ret[7] = css.RackPosition;
                ret[8] = css.RackPlace;
                ret[9] = css.LabelInfo;
                if (!System.String.IsNullOrEmpty(css.TaskNo) && int.Parse(css.TaskNo) > 0)
                {
                    if (System.String.IsNullOrEmpty(css.Fromstation) || System.String.IsNullOrEmpty(css.Tostation))
                    {
                        string[] ss = new string[4];
                        ss = dal.GetTostation(css.TaskNo, "SC");
                        if (ss != null)
                        {
                            css.Fromstation = ss[0];
                            css.Tostation = ss[1];
                        }
                    }
                }
                if (!System.String.IsNullOrEmpty(css.TaskNo2) && int.Parse(css.TaskNo2) > 0)
                {
                    if (System.String.IsNullOrEmpty(css.Fromstation2) || System.String.IsNullOrEmpty(css.Tostation2))
                    {
                        string[] ss = new string[4];
                        ss = dal.GetTostation(css.TaskNo2, "SC");
                        if (ss != null)
                        {
                            css.Fromstation2 = ss[0];
                            css.Tostation2 = ss[1];
                        }
                    }
                }
                ret[4] = css.Fromstation;
                ret[5] = css.Tostation;
                ret[10] = css.SCTaskFlag;
                ret[11] = css.isInitial;
                ret[12] = "";
                ret[13] = css.CraneMode;
                ret[14] = css.isOk;
                ret[15] = css.taskMode.ToString();
                ret[16] = css.TaskNo2;
                ret[17] = css.Fromstation2;
                ret[18] = css.Tostation2;
            }
            return ret;
        }
        public DataTable GetTask()
        {
            string lane = "", executingsc = ""; ;
            bool[] arr = { true, true, true };
            DataTable dt = new DataTable();
            dt.Columns.Add("num", Type.GetType("System.String"));
            dt.Columns.Add("taskno", Type.GetType("System.String"));
            dt.Columns.Add("fromstation", Type.GetType("System.String"));
            dt.Columns.Add("tostation", Type.GetType("System.String"));
            dt.Columns.Add("statostation", Type.GetType("System.String"));
            dt.Columns.Add("distance", Type.GetType("System.String"));
            dt.Columns.Add("priority", typeof(int));//2020.5.17 xj新加列
            dt.Columns.Add("tasktype", Type.GetType("System.String"));
            dt.Columns.Add("BARCODE", Type.GetType("System.String"));
            CRCStatus css = null;
            foreach (CRCObject co in list_srm_object)
            {
                if (co.Port.ToString().Contains("400"))
                {
                    lane = "0";
                    lane += co.ScNo.Substring(co.ScNo.Length - 1, 1);

                    css = list_srm_info.Find(
                        delegate (CRCStatus info)
                        {
                            return info.scno == co.ScNo;
                        }
                    );
                    if (css != null)
                    {
                        lane += css.SCTaskFlag;
                    }
                    else
                    {
                        lane += "0";
                    }
                    DataTable dt_task = null;
                    //DataSet dsSCTask = dal.GetSRMTask(lane);   //
                    DataSet ds = dal.GetM6USRMTask(co.ScNo);   //
                    if (ds != null && ds.Tables.Count > 0)
                        dt_task = ds.Tables[0];
                    if (dt_task != null)
                    {
                        DataTable dts = dt_task.Copy();
                        foreach (DataRow row in dts.Rows)
                        {
                            if (row["taskstatus"].ToString() == "2")
                                executingsc += row["equipmentnumber"].ToString() + ";";
                        }
                        if (taskht != null && taskht.Length > 0)
                        {

                            var SCTaskQuey = from v in dt_task.AsEnumerable() where v.Field<string>("taskstatus") == "0" && css.taskMode == SCTaskMode.Auto select v;

                            if (SCTaskQuey != null && SCTaskQuey.Count() > 0)
                            {
                                DataTable outdt = SCTaskQuey.AsDataView().Table;
                                for (int j = 0; j < outdt.Rows.Count; j++)
                                {
                                    string scnumber = outdt.Rows[j]["equipmentnumber"].ToString();
                                    string fromstation = outdt.Rows[j]["fromstation"].ToString();
                                    string tostation = outdt.Rows[j]["tostation"].ToString();
                                    string taskno = outdt.Rows[j]["Taskno"].ToString();
                                    string tasktype = outdt.Rows[j]["TASKTYPE"].ToString();

                                    if ((tasktype == "Task_InBound" && css.TaskType != "Task_InBound" && css.TaskType != "All") || (tasktype == "Task_OutBound" && css.TaskType != "Task_OutBound" && css.TaskType != "All") || css.TaskType == "None")
                                    {
                                        continue;
                                    }
                                    if (outdt.Rows[j]["taskstatus"].ToString() == "0" && !executingsc.Contains(scnumber))
                                    {
                                        if (CheckStation(fromstation, tostation, taskno) == taskno)//检查当前任务是不是可执行的任务
                                        {
                                            //-------------2021-7-6 林兴煌 如果是出库任务，需要判断一下出库口是否为双工位，双工位则判断两个货叉是否都为空，都为空情况下再出库
                                            if (tostation.Length == 4)
                                            {
                                                string workNo1tostation = converyZoneInfo.Where(x => x.stationNo == tostation).FirstOrDefault().WORKINGLOCATION1;//工位1
                                                if (!string.IsNullOrEmpty(workNo1tostation) && workNo1tostation == tostation)
                                                    workNo1tostation = converyZoneInfo.Where(x => x.stationNo == tostation).FirstOrDefault().WORKINGLOCATION2;//工位2
                                                if (CheckStation(fromstation, workNo1tostation, taskno) != taskno)//检查当前任务是不是可执行的任务
                                                {
                                                    co.BllSrm.WriteLog("S", "堆垛机编号:" + css.scno + "任务:" + taskno + "放货站台" + workNo1tostation + "拒绝放货,请检查站台放货允许信号");
                                                    continue;
                                                }
                                            }
                                            //----------------------------------------------------------------------
                                            taskht[Int32.Parse(css.scno.Remove(0, 3)) - 1] = true;
                                            co.BllSrm.WriteLog("S", "堆垛机编号:" + css.scno + "起点站台：" + fromstation + ";目的站台：" + tostation);
                                            int.TryParse(outdt.Rows[j]["PRIORITY"].ToString(), out var priority);//2020.5.17 xj新加
                                            dt.Rows.Add(new object[] { outdt.Rows[j]["equipmentnumber"].ToString(), taskno, fromstation, tostation, fromstation, outdt.Rows[j]["curpostion"], priority, css.TaskType, outdt.Rows[j]["BARCODE"].ToString() });
                                            //break;
                                        }
                                        else
                                        {
                                            if (fromstation.Length == 4 && tostation.Length > 4)
                                            {
                                                co.BllSrm.WriteLog("S", "堆垛机编号:" + css.scno + "入库站台" + fromstation + "任务号:" + CheckStation(fromstation, tostation, taskno) + "与数据任务号:" + taskno + "不一致");
                                            }
                                            else if (tostation.Length == 4 && fromstation.Length > 4)
                                            {
                                                co.BllSrm.WriteLog("S", "堆垛机编号:" + css.scno + "出库任务:" + taskno + "放货站台" + tostation + "拒绝放货,请检查站台放货允许信号");
                                            }
                                            else if (tostation.Length == 4 && fromstation.Length == 4)
                                            {
                                                co.BllSrm.WriteLog("S", "堆垛机编号:" + css.scno + "摆渡任务:" + taskno + "放货站台" + tostation + "拒绝放货,请检查站台放货允许信号");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return dt;
        }

        public void GetNewTask()
        {
            string lane = "";
            CRCStatus css = null;
            foreach (CRCObject co in list_srm_object)
            {
                if (co.Port.ToString().Contains("400"))
                {
                    lane = "0";
                    lane += co.ScNo.Substring(co.ScNo.Length - 1, 1);

                    css = list_srm_info.Find(
                        delegate (CRCStatus info)
                        {
                            return info.scno == co.ScNo;
                        }
                    );
                    if (css != null)
                    {
                        lane += css.SCTaskFlag;
                    }
                    else
                    {
                        lane += "0";
                    }
                    DataSet dsSCTask = dal.GetSRMTask(lane);   //
                }
            }
        }
        public void WriteLog(string m_strSRMNo, string msg)
        {
            if (msg.Length > 6)
            {
                string flag = msg.Substring(0, 6);
                if (!logHt.Contains(m_strSRMNo))
                {
                    logHt.Add(m_strSRMNo, msg);
                    log.Info(msg);
                }
                else
                {
                    if (logHt[m_strSRMNo].ToString() != msg)
                    {
                        logHt[m_strSRMNo] = msg;
                        log.Info(msg);
                    }
                }
            }
        }
        //验证站台
        private string CheckStation(string fromstation, string tostation, string taskno)
        {
            if (testFlag == 1)//开启测试环境
                return taskno;

            ConveryPLC converyPLC = new ConveryPLC();
            string[] stationinfo;

            if (fromstation.Length == 11 && tostation.Length == 11) //移库
            {
                return taskno;
            }
            else if (fromstation.Length == 4 && tostation.Length == 11) //入库
            {
                stationinfo = converyPLC.ReadStaInfo(fromstation);
                if (stationinfo[5].ToString() != "1" && stationinfo[5].ToString() != "2")
                {
                    return "0";
                }
                return stationinfo[1].ToString().Trim();
            }

            else if (tostation.Length == 4 && fromstation.Length == 11)   //出库
            {
                stationinfo = converyPLC.ReadStaInfo(tostation);
                if (stationinfo[1].ToString().Equals("0") && stationinfo[6].ToString().Equals("1") && stationinfo[8].ToString().Equals("1"))
                {
                    return taskno;
                }
            }
            else if (tostation.Length == 4 && fromstation.Length == 4)   //搬运
            {
                stationinfo = converyPLC.ReadStaInfo(tostation);
                //2021-7-7 林兴煌 同时还要判断起始地址的托盘是否为当前托盘
                string[] stationinfo1 = converyPLC.ReadStaInfo(fromstation);
                //if (stationinfo[1].ToString().Equals("0") && stationinfo[4]!="0")
                if (stationinfo[1].ToString().Equals("0") && stationinfo[6].ToString().Equals("1") && stationinfo[8].ToString().Equals("1") && (stationinfo1[5].ToString() == "1" || stationinfo1[5].ToString() == "2"))
                {
                    return stationinfo1[1].ToString().Trim();
                }
            }
            return "0";
        }
    }
}

